function insertSort(arr) {
    for (let i = 1; i < arr.length; i++) {
        let key = arr[i];
        let j = i - 1;
        for (; j >= 0 && arr[j] > key; j--) {
            arr[j + 1] = arr[j];
        }
        arr[j + 1] = key;
    }
}

arr = [5, 2, 4, 6, 1, 3];
insertSort(arr);
console.log(arr); // [1, 2, 3, 4, 5, 6]